<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://www.goodfox.com/jsp/tags/power" prefix="p"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%
request.setAttribute("locale",request.getLocale());
%>
<script type="text/javascript">
var tdTips1 = "四至名称",
	tdTips2 = "坐标信息";
function tdInputBlur(_obj){
	var val = $(_obj).val(),
		idx = $(_obj).closest("td").index();
	//未输入时恢复提示
	if(val==""&&idx==1){
		val = tdTips1;
	}
	if(val==""&&idx==2){
		val = tdTips2;
	}
	$(_obj).next().val(val);
	$(_obj).prev().text(val).show();
	$(_obj).remove();
}

$.fn.addFBTr = function(){
	//按标签页为name添加数字，从1开始
	var div = $(".forestInfoTabs>.tabsContent>div").has(this),
		num = div.index()+1,
		tr = '\
		<tr class="fbNewAdded">\
			<td width="22"><input type="checkbox" name="fbCheck*'+num+'" class="checkboxCtrl"></td>\
			<td class="tdInput"><div><input type="text" name="rights_add_fourName*'+num+'" class="textInput" value="" size="50"/></div></td>\
			<td class="tdInput"><div><input type="text" name="rights_add_corXY*'+num+'" class="textInput" value="" size="50"/></div></td>\
		</tr>';
	$(this).click(function(){
		$(".fourBoundaries .gridTbody tbody",div).append(tr);
		$(".fbNewAdded").bind("mouseover",function(){
			$(this).addClass("hover");
		}).bind("mouseout",function(){
			$(this).removeClass("hover");
		}).bind("click",function(){
			$(this).addClass("selected").siblings().removeClass("selected");
		}).siblings().bind("click",function(){
			$(this).siblings().removeClass("selected");
		});
	});
};

$.fn.removeFBTr = function(){
	var div = $(".forestInfoTabs>.tabsContent>div").has(this);
	$(this).click(function(){
		var tr = $(".fourBoundaries .gridTbody tbody tr",div);
		if($("input:checked",tr).length>0){
			$("input:checked",tr).closest("tr").remove();
		}else if(tr.hasClass("selected")){
			$("tr.selected",tr.parent()).remove();
		}else{
			alertMsg.warn("没有选择任何条目！");
		}
	});
};

function switchTabs(_obj){
	$(".forestInfoTabs .tabsHeader ul li").removeClass("selected");
	$(".forestInfoTabs .tabsContent>div").hide();
	if(_obj==undefined||_obj==null){
		$(".forestInfoTabs .tabsHeader ul li:last").addClass("selected");
		$(".forestInfoTabs .tabsContent>div:last").show();
	}else{
		var idx = $(".forestInfoTabs .tabsHeader ul li").index(_obj);
		$(".forestInfoTabs .tabsHeader ul li").eq(idx).addClass("selected");
		$(".forestInfoTabs .tabsContent>div").eq(idx).show();
	}
}

function addRightPhoto(num,showPhotoPath,photoIdPath){
	var signIndex=photoIdPath.indexOf(";");
	var photoId=photoIdPath.substring(0,signIndex);
	var photoPath=photoIdPath.substr(signIndex+1);
	li = '\
	<li style="float:left;border:1px solid #ccc;padding:2px;margin:5px;">\
		<input name="photoIdPaths" value="'+photoIdPath+'" type="checkbox"/>\
		<input name="rights_add_photoId*'+num+'" value="'+photoId+'" type="hidden"/>\
		<input name="rights_add_photoPath*'+num+'" value="'+photoPath+'" type="hidden"/>\
		<img src="'+showPhotoPath+'" width="135" height="95"/>\
	</li>';
	$("#photoContent"+num).append(li);
}

$(function(){
	$("#addForestInfo").click(function(){
		var num = $(".forestInfoTabs .tabsHeaderContent ul li").size()+1,
			sw = '<li><a href="javascript:;"><span>林地信息'+num+'</span></a></li>',
			ct = $(".forestInfoTabs .tabsContent>div").eq(0).clone(true);
		$(".forestInfoTabs .tabsHeaderContent ul").append(sw);
		$(".forestInfoTabs .tabsContent").append(ct);
		switchTabs();
		$(".raaItems",ct).attr("id","rights_add_atrId*"+num).attr("name","rights_add_atrId*"+num);
		$(".fourBoundaries .toolBar a.add",ct).attr("id","addFB"+num).addFBTr();
		$(".fourBoundaries .toolBar a.delete",ct).attr("id","removeFB"+num).removeFBTr();
		$(".fourBoundaries .gridHeader input.checkboxCtrl",ct).attr("group","fbCheck*"+num);
		$(".fourBoundaries .gridTbody tbody",ct).empty();
		$(".photoContent ul",ct).attr("id","photoContent"+num).empty();
		$(":input",ct).not(":button, :submit, :checkbox").val("");
		$(":input",ct).not(":button, :submit,").removeAttr("checked").removeAttr("selected");
		
		var href=$("#showAddPhoto",ct).attr("href");
		href=href.substring(0,href.indexOf("tabIndex=")+9)+num;
		$("#showAddPhoto",ct).attr("href",href);
	});
	$(".forestInfoTabs .tabsHeader ul li").live("click",function(){
		switchTabs(this);
	});
	
	$("[id^='addFB']").each(function(){
		$(this).addFBTr();
	});
	$("[id^='removeFB']").each(function(){
		$(this).removeFBTr();
	});
	
	//文字的一些响应
// 	$(".tdInput span").live("click",function(){
// 		if($(this).text()==tdTips1||$(this).text()==tdTips2){
// 			$(this).text("");
// 		}
// 		var ipt = "<input type='text' value='"+$(this).text()+"' />";
// 		$(ipt).insertAfter(this).focus();
// 		$(this).hide();
// 	}).live("mouseover",function(){
// 		$(this).css({
// 			"background":"#fff",
// 			"border":"1px solid #aaa",
// 			"padding":"2px"
// 		});
// 	}).live("mouseout",function(){
// 		$(this).css({
// 			"background":"none",
// 			"border":"none",
// 			"padding":"0"
// 		});
// 	});
// 	$(".tdInput input:text").live("blur",function(){
// 		tdInputBlur(this);
// 	});
});

function rightsAddSubmit(formObj){
	$("input[name^='rights_add']").each(function(){
		if($(this).val()==""){
			$(this).attr("value"," ");
		}
	});
	return validateCallback(formObj,navTabAjaxDone);
}
</script>

<div class="pageContent">
	<form method="post" action="<c:url value="/rights/rightsAdd.shtml"/>" class="pageForm required-validate" onsubmit="return rightsAddSubmit(this);">
		<div class="pageFormContent" layoutH="56">
			<p>
				<label>林权证编号：</label>
				<input type="text" name="rights_add_rigCode"  id="rights_add_rigCode" size="30"/>
			</p>
			<p>
				<label>林权证号：</label>
				<input type="text" name="rights_add_rigNumber"  id="rights_add_rigNumber" size="30"/>
			</p>
			<p>
				<label>身份证号：</label>
				<input type="text" name="rights_add_idCards"  id="rights_add_idCards" size="30"/>
			</p>
			<p>
				<label>法定代表人：</label>
				<input type="text" name="rights_add_legal"  id="rights_add_legal" size="30">
			</p>
			<p style="width:760px">
				<label>通讯地址：</label>
				<input type="text" name="rights_add_address"  id="rights_add_address" size="93"/>
			</p>
			<p style="width:760px">
				<label>单位（个人）：</label>
				<input type="text" name="rights_add_unit"  id="rights_add_unit" size="93">
			</p>
			
			<div style="clear:both;"></div>
			
			<div class="panelBar" style="border-left: 1px solid #B8D0D6;border-right: 1px solid #B8D0D6;border-bottom:none;">
				<ul class="toolBar">
					<li><span>林地信息</span></li>
					<li class="line">line</li>
					<li><a class="add" href="#" id="addForestInfo"><span><spring:message code="search.btnGoAdd"/></span></a></li>
				</ul>
			</div>
			<div class="tabs forestInfoTabs">
				<div class="tabsHeader">
					<div class="tabsHeaderContent">
						<ul>
							<li><a href="javascript:;"><span>林地信息1</span></a></li>
						</ul>
					</div>
				</div>
				<div class="tabsContent" style="background:#fff;">
					<!-- 林地信息1 -->
					<div>
						<p>
							<label>申请表编号：</label>
							<input type="text" name="rights_add_appNumber" id="rights_add_appNumber" size="30"/>
						</p>
						<p>
							<label>登记类型：</label>
							<select name="rights_add_rstType" id="rights_add_rstType">
			                	<option value="">--请选择--</option>
			          			<c:forEach items="${rstTypeList}" var="atrRstType">
			           				<option value="${atrRstType.atrValue}">${atrRstType.atrName}</option>
			           			</c:forEach>
			                </select>
						</p>
						<p>
							<label>是否抵押：</label>
							<select name="rights_add_mortgage" id="rights_add_mortgage">
			                	<option value="">--请选择--</option>
			                	<option value="1">是</option>
			                	<option value="0">否</option>
			          		</select>
						</p>
						<p>
							<label>是否退耕还林地：</label>
							<select name="rights_add_backForest" id="rights_add_backForest">
			                	<option value="">--请选择--</option>
			                	<option value="1">是</option>
			                	<option value="0">否</option>
			          		</select>
						</p>
						<p>
							<label>林地所有权权利人：</label>
							<select name="rights_add_fstOwn" id="rights_add_fstOwn">
			                	<option value="">--请选择--</option>
			          			<c:forEach items="${fstOwnList}" var="atrFstOwn">
			           				<option value="${atrFstOwn.atrValue}">${atrFstOwn.atrName}</option>
			           			</c:forEach>
			                </select>
						</p>
						<p>
							<label>林地使用权权利人：</label>
							<input type="text" name="rights_add_fstUse" id="rights_add_fstUse" size="30"/>
						</p>
						<p>
							<label>森林或林木所有权权利人：</label>
							<input type="text" name="rights_add_woodOwn" id="rights_add_woodOwn" size="30">
						</p>
						<p>
							<label>森林或林木使用权权利人：</label>
							<input type="text" name="rights_add_woodUse" id="rights_add_woodUse" size="30">
						</p>
						<p>
							<label>坐落：</label>
							<input type="hidden" name="rights_add.areaId" id="rights_add_areaId" value=""/>
	                    	<input type="text" name="rights_add.areaName" id="rights_add_areaName" value="" readonly="readonly"/>
                    		<a class="btnLook" href="<c:url value="/rights/goAreaLookup.shtml"/>" lookupGroup="rights_add">选择所属地区</a>
		                    <a class="btnClean" href="javascript:;" onclick="$('#rights_add_areaId').val('');$('#rights_add_areaName').val('');">清空</a>
						</p>
						<p>
							<label>小地名：</label>
							<input type="text" name="rights_add_smallTo" id="rights_add_smallTo" size="30">
						</p>
						<p>
							<label>林班：</label>
							<input type="text" name="rights_add_fstClass" id="rights_add_fstClass" size="30">
						</p>
						<p>
							<label>小班：</label>
							<input type="text" name="rights_add_smallCls" id="rights_add_smallCls" size="30">
						</p>
						<p>
							<label>面积（亩）：</label>
							<input type="text" name="rights_add_acreage" id="rights_add_acreage" size="30">
						</p>
						<dl class="nowrap">
							<dt>主要树种：</dt>
							<dd>
							<c:forEach items="${speciesList}" var="atrSpecies">
							<input type="checkbox" class="checkbox raaItems" name="rights_add_atrId*1" id="rights_add_atrId*1" value="${atrSpecies.atrId}">${atrSpecies.atrName}&nbsp;&nbsp;
							</c:forEach>
							</dd>
						</dl>
						<p>
							<label>蓄积或株数：</label>
							<input type="text" name="rights_add_treesNum" id="rights_add_treesNum" size="30">
						</p>
						<p>
							<label>造林年度：</label>
							<input class="Wdate" type="text" id="rights_add_affDate" name="rights_add_affDate" onFocus="WdatePicker({dateFmt:'yyyy'})" readonly="readonly">
						</p>
						<p>
							<label>地类：</label>
							<select name="rights_add_landType" id="rights_add_landType">
			                	<option value="">--请选择--</option>
			          			<c:forEach items="${landTypeList}" var="atrLandType">
			           				<option value="${atrLandType.atrValue}">${atrLandType.atrName}</option>
			           			</c:forEach>
			                </select>
						</p>
						<p>
							<label>森林分类：</label>
							<select name="rights_add_fstType" id="rights_add_fstType">
			                	<option value="">--请选择--</option>
			          			<c:forEach items="${fstTypeList}" var="atrFstType">
			           				<option value="${atrFstType.atrValue}">${atrFstType.atrName}</option>
			           			</c:forEach>
			                </select>
						</p>
						<p>
							<label>林种：</label>
							<select name="rights_add_fstSpecies" id="rights_add_fstSpecies">
			                	<option value="">--请选择--</option>
			          			<c:forEach items="${fstSpeciesList}" var="atrFstSpecies">
			           				<option value="${atrFstSpecies.atrValue}">${atrFstSpecies.atrName}</option>
			           			</c:forEach>
			                </select>
						</p>
						<p>
							<label>林地使用期（年）：</label>
							<input type="text" name="rights_add_fstUseDate" id="rights_add_fstUseDate" size="30">
						</p>
						<p>
							<label>终止日期：</label>
							<input class="Wdate" type="text" id="rights_add_endDate" name="rights_add_endDate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly">
						</p>
						<p>
							<label>坡度：</label>
							<input type="text" name="rights_add_slope" id="rights_add_slope" size="30"/>
						</p>
						<p>
							<label>坡向：</label>
							<input type="text" name="rights_add_aspect" id="rights_add_aspect" size="30"/>
						</p>
						<p>
							<label>档案柜编号：</label>
							<input type="text" name="rights_add_cabinetNum" id="rights_add_cabinetNum" size="30"/>
						</p>
						
						<div class="divider"></div>
						<div class="pageContent fourBoundaries" style="border-left: 1px solid #B8D0D6;border-right: 1px solid #B8D0D6;width:70%">
							<div class="panelBar">
								<ul class="toolBar">
									<li><span>四至</span></li>
									<li class="line">line</li>
									<li><a class="add" href="#" id="addFB1"><span><spring:message code="search.btnGoAdd"/></span></a></li>
									<li><a class="delete" href="#" id="removeFB1"><span><spring:message code="search.btnRemove"/></span></a></li>
								</ul>
							</div>
							<table class="table" width="100%">
								<thead>
									<tr>
										<th width="22"><input type="checkbox" group="fbCheck*1" class="checkboxCtrl"></th>
										<th>名称</th>
										<th>坐标</th>
									</tr>
								</thead>
								<tbody></tbody>
							</table>
						</div>
						<div class="divider"></div>
						<div class="pageContent" style="border-left: 1px solid #B8D0D6;border-right: 1px solid #B8D0D6;border-bottom: 1px solid #B8D0D6;width:70%">
							<div class="panelBar">
								<ul class="toolBar">
									<li><span>图片</span></li>
									<li class="line">line</li>
									<li><a class="add" id="showAddPhoto" href="<c:url value="/rights/goRightsPhotoAdd.shtml"/>?tabIndex=1" target="dialog" width="420"><span><spring:message code="search.btnGoAdd"/></span></a></li>
									<li><a class="delete" title="确实要删除这些记录吗?" target="selectedTodo" rel="photoIdPaths" href="<c:url value="/rights/photoRemoveBat.shtml"/>"><span><spring:message code="search.btnRemove"/></span></a></li>
								</ul>
							</div>
							<div class="photoContent">
								<ul id="photoContent1">
								</ul>
							</div>
						</div>
						<div class="divider"></div>
						<dl class="nowrap">
							<dt>主要权利依据：</dt>
							<dd><textarea rows="2" cols="80" name="rights_add_basis" id="rights_add_basis" class="textInput"></textarea></dd>
						</dl>
						<dl class="nowrap">
							<dt>林权共有者说明：</dt>
							<dd><textarea rows="2" cols="80" name="rights_add_explain" id="rights_add_explain" class="textInput"></textarea></dd>
						</dl>
						<dl class="nowrap">
							<dt>注记：</dt>
							<dd><textarea rows="2" cols="80" name="rights_add_note" id="rights_add_note" class="textInput"></textarea></dd>
						</dl>
						<p>
							<label>外业调查人：</label>
							<input type="text" name="rights_add_invPerson" id="rights_add_invPerson" size="30"/>
						</p>
						<p>
							<label>经办人：</label>
							<input type="text" name="rights_add_hdePerson" id="rights_add_hdePerson" size="30"/>
						</p>
						<p>
							<label>负责人：</label>
							<input type="text" name="rights_add_crgPerson" id="rights_add_crgPerson" size="30"/>
						</p>
						<p>
							<label>发证日期：</label>
							<input class="Wdate" type="text" id="rights_add_issueDate" name="rights_add_issueDate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly">
						</p>
					</div>
				</div>
				<div class="tabsFooter">
					<div class="tabsFooterContent"></div>
				</div>
			</div>
					
			<div class="divider"></div>
		</div>
		<div class="formBar">
			<ul>
        		<c:if test="${p:isPower('/rights/rightsAdd.shtml',sessionScope.loginAccount)}">
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit"><spring:message code="add.btnAdd"/></button></div></div></li>
				</c:if>
				<li><div class="button"><div class="buttonContent"><button type="button" class="close"><spring:message code="page.btnClose"/></button></div></div></li>
			</ul>
		</div>
	</form>
</div>
